/*
 * tab 我的任务、团队回顾
 */
import 'package:flutter/material.dart';
import './myTaskWidget/myTaskWidget.dart'; // 我的任务
import './teamReview/teamReview.dart'; // 团队回顾
import './personal/personal.dart'; // 个人

class IndexWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // body is the majority of the screen.
      body: BottomNavigationWidget(),
    );
  }
}

/*
 * 底部菜单
*/
class BottomNavigationWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => BottomNavigationWidgetState();
}

class BottomNavigationWidgetState extends State<BottomNavigationWidget> {
  int _currentIndex = 0;

  var _pageController = PageController();
  var _pages;
  @override
  void initState() {
    _pages = [
      new MyTask(),
      new TeamReview(),
      new Personal()
    ];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              Icons.person_add,
            ),
            title: Text(
              '我的任务',
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.rate_review,
            ),
            title: Text(
              '团队回顾',
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.people,
            ),
            title: Text(
              '团队风采',
            ),
          )
        ],
        currentIndex: _currentIndex,
        onTap: (int index) {
          _pageController.jumpToPage(index);
        },
      ),
      body: Container(
        child: PageView.builder(
          //要点
          physics: NeverScrollableScrollPhysics(),
          //禁止页面左右滑动切换
          controller: _pageController,
          onPageChanged: _pageChanged,
          //回调函数
          itemCount: _pages.length,
          itemBuilder: (context, index) => _pages[index],
        ),
      ),
    );
  }

  void _pageChanged(int index) {
    setState(() {
      if (_currentIndex != index) _currentIndex = index;
    });
  }
}
